/*
 *  Beam.cpp
 *  
 *	Version 1.0
 *  Created by Nicholas Blecha on 9/25/10.
 *  Copyright 2010 Michigan Technological University. All rights reserved.
 *
 */

#include "Beam.h"

int Beam::getDamage() {
	return damage;
}

int Beam::getSpeed() {
	return speed;
}

void Beam::autoMove() {
	position.x -= (int) (speed * cos(angle+M_PI/2));
	position.y -= (int) (speed * sin(angle+M_PI/2));
}

void Beam::show() {
	if (rnd!=NULL)
		rnd->drawSurface(&position, radiansToDegrees(angle), texId);
}

void Beam::show(int mapX, int mapY){
	if (rnd!=NULL)
		drawPos->x=position.x-mapX;
		drawPos->y=position.y-mapY;
		rnd->drawSurface(drawPos, radiansToDegrees(angle), texId);
}

void Beam::setActive(bool a) {
	active = a;
}

void Beam::initialize(int dmg, int spd, float a, int x, int y) {
	damage = dmg;
	speed = spd;
	angle = a;
	position.x = x;
	position.y = y;
}

/*void Beam::setImage(std::string p) {
	if(strcmp(path.c_str(), p.c_str()) != 0)
	{
	path = p;
	if (image!=NULL) {
		SDL_FreeSurface(image);
		image=NULL;
	}
	image = rnd->loadImage(path);
	if (image==NULL)
		throw "Failed to load image";
	else {
		texId = rnd->createTexture(image);
	}
	}
}
*/

void Beam::setup() {
	image = NULL;
	path = "Images//laser0.png";
	image = rnd->loadImage(path);
	texId = rnd->createTexture(image);

	position.w = image->w;
	position.h = image->h;

	drawPos->w=image->w;
	drawPos->h=image->h;
}

Beam::Beam(Renderer *rend, int i) : Sprite() {
	rnd = rend;
	id = i;	
	damage = 0;
	speed = 0;
	angle = 0;
	active = false;
	path = "";

	drawPos=new SDL_Rect();

	setup();
}

Beam::~Beam() {
	SDL_FreeSurface(image);
	delete drawPos;
}
